package com.thinksns.sociax.t4.model;

import com.thinksns.sociax.t4.util.LogUtils;
import com.thinksns.sociax.thinksnsbase.bean.SociaxItem;
import com.thinksns.sociax.thinksnsbase.exception.DataInvalidException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhiyicx on 2017/5/11.
 */

public class ModelEventDetail extends SociaxItem {
//    eid	活动id
//    name	活动标题
//    stime	开始时间啊
//    etime	结束时间
//    area	地区
//    city	城市
//    location	地址
//    place	场所
//    image	封面
//    manNumber	活动需要的人数
//    remainder	活动剩余名额，如果活动人数为空或者0，则表示不限制活动名额
//    price	活动价格
//    tips	价格说明
//    cid	分类id
//    cate	分类名称
//    audit	报名是否需要审核
//    content	活动详情
//    uid	发布者uid
//    enrollment	当前用户是否已经报名
//    star	当前用户是否关注了该活动

//    user	发布者信息
//    enrollmentUsers	参与活动的人列表

    private String eid;
    private String name;
    private long stime;
    private long etime;
    private String area;
    private String city;
    private String location;
    private String place;
    private String image;
    private String manNumber;
    private String remainder;
    private String price;
    private String tips;
    private String cid;
    private String cate;
    private String audit; // 活动报名是否需要审核 0-不审核，1-需审核
    private String content;
    private String uid;
    private boolean enrollment;
    private boolean star;
    private String latitude;
    private String longitude;

    private List<ModelVideo> videoList;
    private List<String> imageList;

    private ModelUser applyUser;
    private List<ModelUser> joinUsers;
    /* 报名状态  -1：未报名，0：未审核，1：已报名  enrollment 将会被废弃，add on 8.11.2017*/
    private String enrollment_status;
    public List<ModelVideo> getVideoList() {
        return videoList;
    }

    public void setVideoList(JSONArray ja) {
        if (ja == null) return;
        try {
            videoList = new ArrayList<>();
            for (int i = 0; i < ja.length(); i++) {
                videoList.add(new ModelVideo(ja.getJSONObject(i)));
            }
        } catch (JSONException e) {
            LogUtils.logE("modelEventDetail videoList jsonException");
            e.printStackTrace();
        }
    }

    public List<String> getImageList() {
        return imageList;
    }

    public void setImageList(JSONArray ja) {
        if (ja == null) return;
        try {
            imageList = new ArrayList<>();
            for (int i = 0; i < ja.length(); i++) {
                imageList.add(ja.getString(i));
            }
        } catch (JSONException e) {
            LogUtils.logE("modelEventDetail videoList jsonException");
            e.printStackTrace();
        }
    }

    public ModelUser getApplyUser() {
        return applyUser;
    }

    public void setApplyUser(JSONObject jsonObject) {
        if (jsonObject == null) return;
        try {
            this.applyUser = new ModelUser(jsonObject);
        } catch (DataInvalidException e) {
            e.printStackTrace();
        }
    }

    public List<ModelUser> getJoinUsers() {
        return joinUsers;
    }

    public void setJoinUsers(JSONArray jsonArray) {
        if (jsonArray == null || jsonArray.isNull(0)) return;
        if (joinUsers == null) joinUsers = new ArrayList<>();
        for (int i = 0; i < jsonArray.length(); i++) {
            try {
                joinUsers.add(new ModelUser(jsonArray.getJSONObject(i)));
            } catch (DataInvalidException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    public void setJoinUsers(List<ModelUser> users) {
        if (users == null)
            this.joinUsers = new ArrayList<>();
        else
            this.joinUsers = users;
    }

    @Override
    public boolean checkValid() {
        return false;
    }

    @Override
    public String getUserface() {
        return null;
    }

    public String getEid() {
        return eid;
    }

    public String getName() {
        return name;
    }

    public long getStime() {
        return stime;
    }

    public long getEtime() {
        return etime;
    }

    public String getArea() {
        return area;
    }

    public String getCity() {
        return city;
    }

    public String getLocation() {
        return location;
    }

    public String getPlace() {
        return place;
    }

    public String getImage() {
        return image;
    }

    public String getManNumber() {
        return manNumber;
    }

    public String getRemainder() {
        return remainder;
    }

    public String getPrice() {
        return price;
    }

    public String getTips() {
        return tips;
    }

    public String getCid() {
        return cid;
    }

    public String getCate() {
        return cate;
    }

    public String getAudit() {
        return audit;
    }

    public String getContent() {
        return content;
    }

    public String getUid() {
        return uid;
    }

    public boolean getEnrollment() {
        return enrollment;
    }

    public boolean getStar() {
        return star;
    }

    public void setStar(boolean isStar) {
        this.star = isStar;
    }

    public void setEnrollment(boolean enrollment) {
        this.enrollment = enrollment;
    }

    public void setAudit(String audit) {
        this.audit = audit;
    }

    public String getEnrollment_status() {
        return enrollment_status;
    }

    public void setEnrollment_status(String enrollment_status) {
        this.enrollment_status = enrollment_status;
    }

    public String getLatitude() {
        return latitude;
    }

    public String getLongitude() {
        return longitude;
    }

    public static class ModelVideo {
        private String url;
        private String imgurl;

        public ModelVideo(JSONObject o) {
            if (o == null) return;
            if (o.has("url")) {
                url = o.optString("url");
            }
            if (o.has("imgurl")) {
                imgurl = o.optString("imgurl");
            }
        }

        public String getUrl() {
            return url;
        }

        public String getImgurl() {
            return imgurl;
        }

        @Override
        public String toString() {
            return "ModelVideo{" +
                    "url='" + url + '\'' +
                    ", imgurl='" + imgurl + '\'' +
                    '}';
        }
    }

    @Override
    public String toString() {
        return "ModelEventDetail{" +
                "eid='" + eid + '\'' +
                ", name='" + name + '\'' +
                ", stime=" + stime +
                ", etime=" + etime +
                ", area='" + area + '\'' +
                ", city='" + city + '\'' +
                ", location='" + location + '\'' +
                ", place='" + place + '\'' +
                ", image='" + image + '\'' +
                ", manNumber='" + manNumber + '\'' +
                ", remainder='" + remainder + '\'' +
                ", price='" + price + '\'' +
                ", tips='" + tips + '\'' +
                ", cid='" + cid + '\'' +
                ", cate='" + cate + '\'' +
                ", audit='" + audit + '\'' +
                ", content='" + content + '\'' +
                ", uid='" + uid + '\'' +
                ", enrollment=" + enrollment +
                ", star=" + star +
                ", latitude='" + latitude + '\'' +
                ", longitude='" + longitude + '\'' +
                ", videoList=" + videoList +
                ", imageList=" + imageList +
                ", applyUser=" + applyUser +
                ", joinUsers=" + joinUsers +
                '}';
    }
}
